/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  Gabber 2
 *  Based on Gabber, Copyright (c) 1999-2002 Dave Smith & Julian Missig
 *  Copyright (c) 2003 Julian Missig
 */
#include <gtkmm/eventbox.h>
#include <gtkmm/image.h>
#include <gtkmm.h>
#include "StatusIcon.h"
#include "pixmaps.h"
StatusIcon::StatusIcon(MainWindow* gwin)
     : _gwin(gwin)
{
     // actually, apparently it doesn't matter whether there is a dock or not
     // the docklet will auto-appear when it's time
     init();
//     init_queue();
}

StatusIcon::~StatusIcon()
{
    // Gtkmm cleans up for us.
}

void StatusIcon::init()
{
     _status_icon_egg = egg_tray_icon_new(("Cyclone"));
     _status_icon = Glib::wrap(GTK_CONTAINER(_status_icon_egg));
//     _status_icon ->signal_delete_event().connect(slot(*this, &StatusIcon::on_delete_event));

     // Add the event box
     _evt_status  = new Gtk::EventBox();
//     _evt_status  ->set_shadow_type(Gtk::SHADOW_NONE);
     _status_icon->add(*_evt_status);
     _evt_status ->add_events(Gdk::BUTTON_PRESS_MASK);
     _evt_status ->signal_button_press_event().connect(
    		sigc::mem_fun(*this, &StatusIcon::on_button_press));

//=============================================
//this need replace with my func
	pixUser[0] = getPix("menu_online.png");
	pixUser[2] = getPix("menu_away.png");
	pixUser[3] = getPix("menu_hidden.png");
	pixUser[1] = getPix("menu_away.png");
	tooltip[0] = "在线";
	tooltip[2] = "离线";
	tooltip[3] = "隐身";
	tooltip[1] = "未连接";
     _img_status = Gtk::manage(new class Gtk::Image(pixUser[0]));
     _evt_status ->add(*_img_status);
     _img_status ->show();
     _evt_status ->show();
     _status_icon->show();

}

void StatusIcon::on_status_change(int status,Glib::ustring nickname)
{
  //   printf("status=%d\n",status);
     _img_status->set(pixUser[status]);
     // Set the tooltip
     _tips.unset_tip(*_evt_status);
     _tips.set_tip(*_evt_status, nickname+tooltip[status]);
     
}

bool StatusIcon::on_button_press(GdkEventButton* e)
{
     // Determine if we should show/hide the main window or popup menu
	printf("I am here");
     if (e->type == GDK_BUTTON_PRESS)
     {
     //this seem not completed yet.yeah
	  if (e->button == 1){
	 //	printf("going to hide or show!\n"); 
	  //this seems need replacement
               _gwin->toggle_visibility();
	  }
          else if (e->button == 3)
          {
               // XXX: popup menu
          }
     }
     return false;
}
